package cn.dxc.demo.handler;

import cn.dxc.demo.common.ResultMapUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//对加了@Controller注解的方法进行拦截处理 AOP的实现
@ControllerAdvice
public class AllExceptionHandler {

    @ResponseBody //返回json数据
    @ExceptionHandler(Exception.class)//进行异常处理，处理Exception.class的异常
    public Object doException(Exception ex){
        ex.printStackTrace();
        return ResultMapUtil.getHashMapInfo("系统异常",-999,null);
    }
}